

import javax.swing.*;
import javax.swing.plaf.FontUIResource;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Objects;

public class WindowOneListener implements ActionListener {
    Teacher teacher = new Teacher();
    WindowOne windowOne;
    WindowTwo windowTwo;

    public void setWindowOne(WindowOne windowOne) {
        this.windowOne = windowOne;
    }

    void initOne() {
        UIManager.put("OptionPane.buttonFont", new FontUIResource(new Font("宋体", Font.BOLD, 12)));
        UIManager.put("Button.background", Color.white);
        UIManager.put("Button.borderPainted", false);
        UIManager.put("OptionPane.messageFont", new FontUIResource(new Font("宋体", Font.BOLD, 14)));
        JOptionPane.showMessageDialog(null, "用户名或密码填写错误，请重新填写！", "错误提醒", JOptionPane.ERROR_MESSAGE);
    }

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == windowOne.passwordField || e.getSource() == windowOne.button) {
            System.out.println(teacher.password[1]);
          if (Objects.equals(teacher.user[0], windowOne.textField.getText()) && Objects.equals(teacher.password[0], (new String(windowOne.passwordField.getPassword())))) {
              windowTwo = new WindowTwo();
              windowOne.dispose();
          }else if (Objects.equals(teacher.user[1], windowOne.textField.getText()) && Objects.equals(teacher.password[1], (new String(windowOne.passwordField.getPassword())))) {
              windowTwo = new WindowTwo();
              windowOne.dispose();
          }else if (Objects.equals(teacher.user[2], windowOne.textField.getText()) && Objects.equals(teacher.password[2], (new String(windowOne.passwordField.getPassword())))) {
              windowTwo = new WindowTwo();
              windowOne.dispose();
          }else{
              initOne();
              windowOne.passwordField.setText("");
          }
        }
    }
}
